safe observability integrations#127
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a55066792c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if key == "method": | ||
| value = event.get("method") | ||
| else: | ||
| value = low_cardinality.get(key) | ||
| labels[key] = _safe_label_value(value) |
There was a problem hiding this comment.
Bucket unrecognized HTTP methods before labeling
When DRF_API_LOGGER_METHODS is not configured, event["method"] is the client-supplied request.method; sending random method tokens such as FOO123 will produce a new Prometheus time series for each token because this value is used verbatim as the method label. That undermines the safe low-cardinality guarantee for record_prometheus_metrics; whitelist standard methods or collapse unknown values before putting them in labels.
Useful? React with 👍 / 👎.
| scope = sentry_sdk.Scope.get_current_scope() | ||
| configure_sentry_scope(scope, kwargs) | ||
|
|
||
| API_LOGGER_SIGNAL.listen += enrich_sentry_scope |
There was a problem hiding this comment.
Move Sentry enrichment before error capture
When users wire the Sentry helper exactly as this recipe shows, it will miss the errors it is supposed to annotate: APILoggerMiddleware emits API_LOGGER_SIGNAL only after self.get_response(request) returns, and an exception raised by the view either has already been captured by Sentry or prevents the signal from being emitted at all. In those error paths the tags/context from configure_sentry_scope are absent, so the recipe should use Sentry's request scope, before_send, or middleware before the view is invoked instead of the logger signal.
Useful? React with 👍 / 👎.
No description provided.